﻿<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/font-awesome.min.css" rel="stylesheet" />
<link href="weixin/css/layer.css" rel="stylesheet" />
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/plugins/layer/layer.min.js"></script>
<script src="weixin/js/common.js"></script>
<style>
    table {
        font-size: 15px;
        height: auto;
        width: auto;
        text-align: center
    }

        table th {
            background-color: darkgrey;
            text-align: center !important;
            min-width: 100px
        }

    .red {
        font-weight: bold;
        color: red;
        background-color: wheat;
    }

    .black {
        color: black;
        font-weight: bold;
        background-color: wheat;
    }
    .market{
          background-color: lightyellow;
    }
    .td-left{
        text-align:left;
    }
</style>
<html>
<head>
    <title>时段跟踪报表</title>
</head>
<body>
    <div style="margin-top:5px;margin-left:5px">
        <table border="1" id="report">
            <thead>
            <tr class="market">
                <td colspan="14" class="td-left"><b>数据更新间隔：30分钟(开始时间：0:15)</b></td><td class="center-block"><a class="btn btn-success btn-xs btn-lg">刷新</a></td>
            </tr>
                <tr class="table-title">
                     <%-- <th>项目</th>
                    <th>日期</th>
                    <th>星期</th>
                  <th>零售1部</th>
                    <th>零售2部</th>
                    <th>零售3部</th>
                    <th>零售4部</th>
                    <th>零售5部</th>
                    <th>零售6部</th>
                    <th>零售7部</th>
                    <th>零售8部</th>
                    <th>零售9部</th>
                    <th>零售10部</th>
                    <th>督导自管店</th>
                    <th>总计</th>--%>
                </tr>
            </thead>
            <tbody id="body">
            </tbody>
        </table>
    </div>
</body>
</html>
<script type="text/javascript">
    Number.prototype.toFixed = function (s) {
        return (parseInt(this * Math.pow(10, s) + 0.5) / Math.pow(10, s)).toString();
    }
    $(function () {

        $(".btn-success").on("click", function () {
            loadData();
        });
     
        var loadData = function () {
            var s = layer.load(0, {
                shade: [0.2, '#fff'] //0.1透明度的白色背景
            });

            $.post("weixin/WXActivity/PostHandler.ashx",
                { "action": "TimeTrackingReport" },
                function (data) {
                    var tbody = $("#body");
                    var table_title = $(".table-title");
                    if (data.Success == true) {
                        if (data.Data.length > 1) {
                            var th_mark = "<th>项目</th><th>日期</th><th>星期</th>";
                            data.Data.map(function (sp) {
                                th_mark += "<th>" + sp.ProvinceName + "</th>";
                            });
                            table_title.empty();
                            table_title.append(th_mark);

                            var html = "";
                            var lastweek = data.Data[0].group[0][0].BillDate;
                            var lastweekWeek = data.Data[0].group[0][0].Week;
                            var yestorday = data.Data[0].group[1][0].BillDate;
                            var yestordayWeek = data.Data[0].group[1][0].Week;
                            var today = data.Data[0].group[2][0].BillDate;
                            var todayWeek = data.Data[0].group[2][0].Week;

                            var shopQtyL = "<tr>";
                            var shopQtyY = "<tr>";
                            var shopQtyT = "<tr>";
                            var factAMTL = "<tr>";
                            var factAMTY = "<tr>";
                            var factAMTT = "<tr>";
                            var factAMTN = "<tr>";
                            var factAMTW = "<tr>";
                            var jointRateL = "<tr>";
                            var jointRateY = "<tr>";
                            var jointRateT = "<tr>";
                            var jointRateN = "<tr>";
                            var jointRateW = "<tr>";
                            var saleBillPartQtyL = "<tr>";
                            var saleBillPartQtyY = "<tr>";
                            var saleBillPartQtyT = "<tr>";
                            var saleBillPartQtyN = "<tr>";
                            var saleBillPartQtyW = "<tr>";
                            var kpiQtyL = "<tr>";
                            var kpiQtyY = "<tr>";
                            var kpiQtyT = "<tr>";
                            var kpiQtyN = "<tr>";
                            var kpiQtyW = "<tr>";
                            var unitPriceL = "<tr>";
                            var unitPriceY = "<tr>";
                            var unitPriceT = "<tr>";
                            var unitPriceN = "<tr>";
                            var unitPriceW = "<tr>";
                            var closingL = "<tr>";
                            var closingY = "<tr>";
                            var closingT = "<tr>";
                            var closingN = "<tr>";
                            var closingW = "<tr>";

                            shopQtyL += "<td id= 'ShopQty' rowspan= '3' colspan= '1'><b>店铺数</b></td >";
                            shopQtyL += "<td class='lastweek' rowspan='1' >" + lastweek + "</td>";
                            shopQtyL += "<td class='lastweekWeek' rowspan='1' >" + lastweekWeek + "</td>";
                            shopQtyY += "<td class='yestorday' rowspan='1' >" + yestorday + "</td>";
                            shopQtyY += "<td class='yestordayWeek' rowspan='1' >" + yestordayWeek + "</td>";
                            shopQtyT += "<td class='today' rowspan='1' >" + today + "</td>";
                            shopQtyT += "<td class='todayWeek' rowspan='1' >" + todayWeek + "</td>";

                            factAMTL += "<td id='FactAMT' rowspan='5' ><b>销售金额</b></td>";
                            factAMTL += "<td class='lastweek' rowspan='1' >" + lastweek + "</td>";
                            factAMTL += "<td class='lastweekWeek' rowspan='1' >" + lastweekWeek + "</td>";
                            factAMTY += "<td class='yestorday' rowspan='1' >" + yestorday + "</td>";
                            factAMTY += "<td class='yestordayWeek' rowspan='1' >" + yestordayWeek + "</td>";
                            factAMTT += "<td class='today' rowspan='1' >" + today + "</td>";
                            factAMTT += "<td class='todayWeek' rowspan='1' >" + todayWeek + "</td>";
                            factAMTN += "<td class='lastweek_NeighborhoodCom black' rowspan='1' colspan='2' >临日对比</td>";
                            factAMTW += "<td class='lastweek_WeekCom black' rowspan='1' colspan='2' >周星期对比</td>";

                            jointRateL += "<td id='JointRate' rowspan='5' ><b>连带率</b></td>";
                            jointRateL += "<td class='lastweek' rowspan='1' >" + lastweek + "</td>";
                            jointRateL += "<td class='lastweekWeek' rowspan='1' >" + lastweekWeek + "</td>";
                            jointRateY += "<td class='yestorday' rowspan='1' >" + yestorday + "</td>";
                            jointRateY += "<td class='yestordayWeek' rowspan='1' >" + yestordayWeek + "</td>";
                            jointRateT += "<td class='today' rowspan='1' >" + today + "</td>";
                            jointRateT += "<td class='todayWeek' rowspan='1' >" + todayWeek + "</td>";
                            jointRateN +=
                                "<td class='lastweek_NeighborhoodCom black' rowspan='1' colspan='2' >临日对比</td>";
                            jointRateW += "<td class='lastweek_WeekCom black' rowspan='1' colspan='2' >周星期对比</td>";

                            saleBillPartQtyL += "<td id='SaleBillPartQty' rowspan='5' ><b>销售单数</b></td>";
                            saleBillPartQtyL += "<td class='lastweek' rowspan='1' >" + lastweek + "</td>";
                            saleBillPartQtyL += "<td class='lastweekWeek' rowspan='1' >" + lastweekWeek + "</td>";
                            saleBillPartQtyY += "<td class='yestorday' rowspan='1' >" + yestorday + "</td>";
                            saleBillPartQtyY += "<td class='yestordayWeek' rowspan='1' >" + yestordayWeek + "</td>";
                            saleBillPartQtyT += "<td class='today' rowspan='1' >" + today + "</td>";
                            saleBillPartQtyT += "<td class='todayWeek' rowspan='1' >" + todayWeek + "</td>";
                            saleBillPartQtyN +=
                                "<td class='lastweek_NeighborhoodCom black' rowspan='1' colspan='2' >临日对比</td>";
                            saleBillPartQtyW +=
                                "<td class='lastweek_WeekCom black' rowspan='1' colspan='2'  >周星期对比</td>";

                            kpiQtyL += "<td id='KpiQty' rowspan='5' ><b>客流量</b></td>";
                            kpiQtyL += "<td class='lastweek' rowspan='1' >" + lastweek + "</td>";
                            kpiQtyL += "<td class='lastweekWeek' rowspan='1' >" + lastweekWeek + "</td>";
                            kpiQtyY += "<td class='yestorday' rowspan='1' >" + yestorday + "</td>";
                            kpiQtyY += "<td class='yestordayWeek' rowspan='1' >" + yestordayWeek + "</td>";
                            kpiQtyT += "<td class='today' rowspan='1' >" + today + "</td>";
                            kpiQtyT += "<td class='todayWeek' rowspan='1' >" + todayWeek + "</td>";
                            kpiQtyN += "<td class='lastweek_NeighborhoodCom black' rowspan='1' colspan='2' >临日对比</td>";
                            kpiQtyW += "<td class='lastweek_WeekCom black' rowspan='1' colspan='2' >周星期对比</td>";

                            unitPriceL += "<td id='UnitPrice' rowspan='5' ><b>客单价</b></td>";
                            unitPriceL += "<td class='lastweek' rowspan='1' >" + lastweek + "</td>";
                            unitPriceL += "<td class='lastweekWeek' rowspan='1' >" + lastweekWeek + "</td>";
                            unitPriceY += "<td class='yestorday' rowspan='1' >" + yestorday + "</td>";
                            unitPriceY += "<td class='yestordayWeek' rowspan='1' >" + yestordayWeek + "</td>";
                            unitPriceT += "<td class='today' rowspan='1' >" + today + "</td>";
                            unitPriceT += "<td class='todayWeek' rowspan='1' >" + todayWeek + "</td>";
                            unitPriceN +=
                                "<td class='lastweek_NeighborhoodCom black' rowspan='1'  colspan='2' >临日对比</td>";
                            unitPriceW += "<td class='lastweek_WeekCom black' rowspan='1'  colspan='2' >周星期对比</td>";

                            closingL += "<td id='Closing' rowspan='5' ><b>成交率</b></td>";
                            closingL += "<td class='lastweek' rowspan='1' >" + lastweek + "</td>";
                            closingL += "<td class='lastweekWeek' rowspan='1' >" + lastweekWeek + "</td>";
                            closingY += "<td class='yestorday' rowspan='1' >" + yestorday + "</td>";
                            closingY += "<td class='yestordayWeek' rowspan='1' >" + yestordayWeek + "</td>";
                            closingT += "<td class='today' rowspan='1' >" + today + "</td>";
                            closingT += "<td class='todayWeek' rowspan='1' >" + todayWeek + "</td>";
                            closingN +=
                                "<td class='lastweek_NeighborhoodCom black' rowspan='1' colspan='2'  >临日对比</td>";
                            closingW += "<td class='lastweek_WeekCom black' rowspan='1'  colspan='2' >周星期对比</td>";

                            var thead = $("#report").find("th");


                            thead.each(function() {
                                var $this = this;
                                data.Data.map(function(item) {
                                    if (item.ProvinceName == $this.textContent) {
                                        shopQtyL += "<td class='shopQtyL' rowspan='1' >" +
                                            (item.group[0][0].ShopQty || ' ') +
                                            "</td>";
                                        shopQtyY += "<td class='shopQtyY' rowspan='1' >" +
                                            (item.group[1][0].ShopQty || ' ') +
                                            "</td>";
                                        shopQtyT += "<td class='shopQtyT' rowspan='1' >" +
                                            (item.group[2][0].ShopQty || ' ') +
                                            "</td>";

                                        factAMTL += "<td class='factAMTL' rowspan='1' >" +
                                            (item.group[0][0].FactAMT || ' ') +
                                            "</td>";
                                        factAMTY += "<td class='factAMTY' rowspan='1' >" +
                                            (item.group[1][0].FactAMT || ' ') +
                                            "</td>";
                                        factAMTT += "<td class='factAMTT' rowspan='1' >" +
                                            (item.group[2][0].FactAMT || ' ') +
                                            "</td>";

                                        var nFactAMT = item.group[0][0].NeighborhoodCom_FactAMT.toFixed(2);
                                        var wFactAMT = item.group[0][0].WeekCom_FactAMT.toFixed(2);
                                        if (nFactAMT < 0) {
                                            factAMTN += "<td class='factAMTN red' rowspan='1' >" + nFactAMT + "%</td>";
                                        } else {
                                            factAMTN += "<td class='factAMTN black' rowspan='1' >" + nFactAMT + "%</td>";
                                        }
                                        if (wFactAMT < 0) {
                                            factAMTW += "<td class='factAMTW red' rowspan='1' >" + wFactAMT + "%</td>";
                                        } else {
                                            factAMTW += "<td class='factAMTW black' rowspan='1' >" + wFactAMT + "%</td>";
                                        }

                                        jointRateL += "<td class='jointRateL' rowspan='1' >" +
                                            (Y.checkNull(item.group[0][0].JointRate) ? ' ' : Y.returnFloat(item.group[0][0].JointRate.toFixed(2)))  +
                                            "</td>";
                                        jointRateY += "<td class='jointRateY' rowspan='1' >" +
                                            (Y.checkNull(item.group[1][0].JointRate) ? ' ' : Y.returnFloat(item.group[1][0].JointRate.toFixed(2)))+
                                            "</td>";
                                        jointRateT += "<td class='jointRateT' rowspan='1' >" +
                                            (Y.checkNull(item.group[2][0].JointRate) ? ' ' : Y.returnFloat(item.group[2][0].JointRate.toFixed(2))) +
                                            "</td>";

                                        var nJointRate = item.group[0][0].NeighborhoodCom_JointRate.toFixed(2);
                                        var wJointRate = item.group[0][0].WeekCom_JointRate.toFixed(2);
                                        if (nJointRate < 0) {
                                            jointRateN += "<td class='jointRateN red' rowspan='1' >" +
                                                nJointRate +
                                                "%</td>";
                                        } else {
                                            jointRateN += "<td class='jointRateN black' rowspan='1' >" +
                                                nJointRate +
                                                "%</td>";
                                        }
                                        if (wJointRate < 0) {
                                            jointRateW += "<td class='jointRateW red' rowspan='1' >" +
                                                wJointRate +
                                                "%</td>";
                                        } else {
                                            jointRateW += "<td class='jointRateW black' rowspan='1' >" +
                                                wJointRate +
                                                "%</td>";
                                        }

                                        saleBillPartQtyL += "<td class='saleBillPartQtyL' rowspan='1' >" +
                                            (item.group[0][0].SaleBillPartQty || ' ') +
                                            "</td>";
                                        saleBillPartQtyY += "<td class='saleBillPartQtyY' rowspan='1' >" +
                                            (item.group[1][0].SaleBillPartQty || ' ') +
                                            "</td>";
                                        saleBillPartQtyT += "<td class='saleBillPartQtyT' rowspan='1' >" +
                                            (item.group[2][0].SaleBillPartQty || ' ') +
                                            "</td>";

                                        var nSaleBillPartQty =
                                            item.group[0][0].NeighborhoodCom_SaleBillPartQty.toFixed(2);
                                        var wSaleBillPartQty = item.group[0][0].WeekCom_SaleBillPartQty.toFixed(2);
                                        if (nSaleBillPartQty < 0) {
                                            saleBillPartQtyN += "<td class='saleBillPartQtyN red' rowspan='1' >" +
                                                nSaleBillPartQty +
                                                "%</td>";
                                        } else {
                                            saleBillPartQtyN += "<td class='saleBillPartQtyN black' rowspan='1' >" +
                                                nSaleBillPartQty +
                                                "%</td>";
                                        }
                                        if (wSaleBillPartQty < 0) {
                                            saleBillPartQtyW += "<td class='saleBillPartQtyW red' rowspan='1' >" +
                                                wSaleBillPartQty +
                                                "%</td>";
                                        } else {
                                            saleBillPartQtyW += "<td class='saleBillPartQtyW black' rowspan='1' >" +
                                                wSaleBillPartQty +
                                                "%</td>";
                                        }

                                        kpiQtyL += "<td class='kpiQtyL' rowspan='1' >" +
                                            (item.group[0][0].KpiQty || ' ') +
                                            "</td>";
                                        kpiQtyY += "<td class='kpiQtyY' rowspan='1' >" +
                                            (item.group[1][0].KpiQty || ' ') +
                                            "</td>";
                                        kpiQtyT += "<td class='kpiQtyT' rowspan='1' >" +
                                            (item.group[2][0].KpiQty || ' ') +
                                            "</td>";

                                        var nKpiQty = item.group[0][0].NeighborhoodCom_KpiQty.toFixed(2);
                                        var wKpiQty = item.group[0][0].WeekCom_KpiQty.toFixed(2);
                                        if (nKpiQty < 0) {
                                            kpiQtyN += "<td class='kpiQtyN red' rowspan='1' >" +
                                                nKpiQty +
                                                "%</td>";
                                        } else {
                                            kpiQtyN += "<td class='kpiQtyN black' rowspan='1' >" +
                                                nKpiQty +
                                                "%</td>";
                                        }
                                        if (wKpiQty < 0) {
                                            kpiQtyW += "<td class='kpiQtyW red' rowspan='1' >" +
                                                wKpiQty +
                                                "%</td>";
                                        } else {
                                            kpiQtyW += "<td class='kpiQtyW black' rowspan='1' >" +
                                                wKpiQty +
                                                "%</td>";
                                        }

                                        unitPriceL += "<td class='unitPriceL' rowspan='1' >" +
                                            (Y.checkNull(item.group[0][0].UnitPrice) ? ' ' : (item.group[0][0].UnitPrice.toFixed(0))) +
                                            "</td>";
                                        unitPriceY += "<td class='unitPriceY' rowspan='1' >" +
                                            (Y.checkNull(item.group[1][0].UnitPrice) ? ' ' : (item.group[1][0].UnitPrice.toFixed(0))) +
                                            "</td>";
                                        unitPriceT += "<td class='unitPriceT' rowspan='1' >" +
                                            (Y.checkNull(item.group[2][0].UnitPrice) ? ' ' : (item.group[2][0].UnitPrice.toFixed(0))) +
                                            "</td>";

                                        var nUnitPrice = item.group[0][0].NeighborhoodCom_UnitPrice.toFixed(2);
                                        var wUnitPrice = item.group[0][0].WeekCom_UnitPrice.toFixed(2);
                                        if (nUnitPrice < 0) {
                                            unitPriceN += "<td class='unitPriceN red' rowspan='1' >" +
                                                nUnitPrice +
                                                "%</td>";
                                        } else {
                                            unitPriceN += "<td class='unitPriceN black' rowspan='1' >" +
                                                nUnitPrice +
                                                "%</td>";
                                        }
                                        if (wUnitPrice < 0) {
                                            unitPriceW += "<td class='unitPriceW red' rowspan='1' >" +
                                                wUnitPrice +
                                                "%</td>";
                                        } else {
                                            unitPriceW += "<td class='unitPriceW black' rowspan='1' >" +
                                                wUnitPrice +
                                                "%</td>";
                                        }

                                        closingL += "<td class='closingL' rowspan='1' >" +
                                            (Y.checkNull(item.group[0][0].Closing) ? ' ' : (item.group[0][0].Closing.toFixed(2) +'%')) +
                                            "</td>";
                                        closingY += "<td class='closingY' rowspan='1' >" +
                                            (Y.checkNull(item.group[1][0].Closing) ? ' ' : (item.group[1][0].Closing.toFixed(2) + '%')) +
                                            "</td>";
                                        closingT += "<td class='closingT' rowspan='1' >" +
                                            (Y.checkNull(item.group[2][0].Closing) ? ' ' : (item.group[2][0].Closing.toFixed(2) + '%')) +
                                            "</td>";

                                        var nClosing = item.group[0][0].NeighborhoodCom_Closing.toFixed(2);
                                        var wClosing = item.group[0][0].WeekCom_Closing.toFixed(2);
                                        if (nClosing < 0) {
                                            closingN += "<td class='closingN red' rowspan='1' >" + nClosing + "%</td>";
                                        } else {
                                            closingN += "<td class='closingN black' rowspan='1' >" + nClosing + "%</td>";
                                        }
                                        if (wClosing < 0) {
                                            closingW += "<td class='closingW red' rowspan='1' >" + wClosing + "%</td>";
                                        } else {
                                            closingW += "<td class='closingW black' rowspan='1' >" + wClosing + "%</td>";
                                        }
                                    }
                                });
                            });
                            shopQtyL += "</tr>";
                            shopQtyY += "</tr>";
                            shopQtyT += "</tr>";

                            factAMTL += "</tr>";
                            factAMTY += "</tr>";
                            factAMTT += "</tr>";
                            factAMTN += "</tr>";
                            factAMTW += "</tr>";

                            jointRateL += "</tr>";
                            jointRateY += "</tr>";
                            jointRateT += "</tr>";
                            jointRateN += "</tr>";
                            jointRateW += "</tr>";

                            saleBillPartQtyL += "</tr>";
                            saleBillPartQtyY += "</tr>";
                            saleBillPartQtyT += "</tr>";
                            saleBillPartQtyN += "</tr>";
                            saleBillPartQtyW += "</tr>";

                            kpiQtyL += "</tr>";
                            kpiQtyY += "</tr>";
                            kpiQtyT += "</tr>";
                            kpiQtyN += "</tr>";
                            kpiQtyW += "</tr>";

                            unitPriceL += "</tr>";
                            unitPriceY += "</tr>";
                            unitPriceT += "</tr>";
                            unitPriceN += "</tr>";
                            unitPriceW += "</tr>";

                            closingL += "</tr>";
                            closingY += "</tr>";
                            closingT += "</tr>";
                            closingN += "</tr>";
                            closingW += "</tr>";

                            html += shopQtyL +
                                shopQtyY +
                                shopQtyT +
                                factAMTL +
                                factAMTY +
                                factAMTT +
                                factAMTN +
                                factAMTW +
                                saleBillPartQtyL +
                                saleBillPartQtyY +
                                saleBillPartQtyT +
                                saleBillPartQtyN +
                                saleBillPartQtyW +
                                jointRateL +
                                jointRateY +
                                jointRateT +
                                jointRateN +
                                jointRateW +
                                kpiQtyL +
                                kpiQtyY +
                                kpiQtyT +
                                kpiQtyN +
                                kpiQtyW +
                                unitPriceL +
                                unitPriceY +
                                unitPriceT +
                                unitPriceN +
                                unitPriceW +
                                closingL +
                                closingY +
                                closingT +
                                closingN +
                                closingW;
                            
                            tbody.empty();
                            tbody.append(html);
                        } else {
                            var emptyTable = "<tr><td colspan='15'>暂无数据</td></tr>";
                            tbody.empty();
                            tbody.append(emptyTable);
                        }
                        layer.close(s);
                    }
                    else
                        layer.close(s);
                });
        }
        loadData();
    });
</script>

